/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.asportoonline.tags;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import org.asportoonline.entities.Locale;

/**
 *
 * @author fe
 */
public class DettagliLocaleTag extends SimpleTagSupport {
    private Locale locale;

    /**
     * Get the value of locali
     *
     * @return the value of locali
     */
    public Locale getLocale() {
        return locale;
    }

    /**
     * Set the value of locali
     *
     * @param locali new value of locali
     */
    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    /**
     * Called by the container to invoke this tag. 
     * The implementation of this method is provided by the tag library developer,
     * and handles all tag processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        Locale l = getLocale();
        String[] chiusura = {"Nessuno", "Luned&igrave;", "Marted&igrave;", "Mercoled&igrave;", "Gioved&igrave;", "Venerd&igrave;", "Sabato", "Domenica"};
        
        try {
            
            if(l==null) {   //teoricamente non e' mai null
                out.print("<p>Nessun locale trovato!!</p>");
            }
            else {
                out.print("<table>"
                        + "<tr><th>Nome:</th><td>"+l.getNome()+"</td></tr>"
                        + "<tr><th>Indirizzo:</th><td>"+l.getIndirizzo().getVia()+", "+l.getIndirizzo().getCitta()+"</td></tr>"
                        + "<tr><th>CAP:</th><td>"+l.getIndirizzo().getCap()+"</td></tr>"
                        + "<tr><th>Prima Apertura:</th><td>"+l.getPrimaApertura()+"</td></tr>");
                
                if(l.getSecondaApertura()!=null && !l.getSecondaApertura().isEmpty()) {
                    out.print("<tr><th>Seconda Apertura:</th><td>"+l.getSecondaApertura()+"</td></tr>");
                }
                
                out.print("<tr><th>Distanza massima:</th><td>"+l.getDistanzaMassima()+" km</td></tr>"
                        + "<tr><th>Giorno di chiusura:</th><td>"+chiusura[l.getGiornoChiusura()+1]+"</td></tr>"
                        + "<tr><th>Telefono:</th><td>"+l.getTelefono()+"</td></tr>"
                        + "<tr><th>Indirizzo email:</th><td>"+l.getEmail()+"</td></tr>"
                        + "<tr><th>P.IVA.:</th><td>"+l.getPiva()+"</td></tr>"
                        + "<tr><td><img src=\"img/" + l.getUrlimmagine() + "\" alt=\"locale_img\" height=\"50\" width=\"50\" /></td></tr>"
                        + "</table>");
                out.flush();
            }
        } catch (java.io.IOException ex) {
            throw new JspException("Error in DettagliLocaleTag tag", ex);
        }
    }
}
